var i = 1;
function add_attach(){				
        var email_body = document.getElementById("email_body");
        var add_button = document.getElementById("add_button").previousSibling.previousSibling;
        
        var label=document.createElement('label');
        label.setAttribute('for',"attach_file"+i);
        label.innerHTML="&nbsp;";
        email_body.insertBefore(label,add_button);
        
        var input=document.createElement('input');
        input.setAttribute('type',"file");
        input.setAttribute('name',"attach_file"+i);
        input.setAttribute('id',"attach_file"+i);
        email_body.insertBefore(input,add_button);
        
        var a=document.createElement('a');
        a.setAttribute('href',"#");
        a.setAttribute('onclick',"remove_attach("+i+")");
        a.innerHTML="remove";
        email_body.insertBefore(a,add_button);
        
        var br=document.createElement('br');
        email_body.insertBefore(br,add_button);
        var br=document.createElement('br');
        email_body.insertBefore(br,add_button);			
        
        document.getElementById("attach_length").value=i;
        i++;
}

function remove_attach(j){
        var email_body = document.getElementById("email_body");
        var remove_elem1 = document.getElementById("attach_file"+j);
        var remove_elem2 = remove_elem1.previousSibling;
        var remove_elem3 = remove_elem1.nextSibling;
        var remove_elem4 = remove_elem3.nextSibling;
        var remove_elem5 = remove_elem4.nextSibling;
        email_body.removeChild(remove_elem1);
        email_body.removeChild(remove_elem2);
        email_body.removeChild(remove_elem3);
        email_body.removeChild(remove_elem4);
        email_body.removeChild(remove_elem5);
    }
